package com.imooc.common.structure.lottery;

import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

import static com.imooc.common.structure.lottery.DrawLotteryUtil.drawGift;

public class MyTest {

    @Test
    public void run1(){
        Gift iphone = new Gift();
        iphone.setId(101);
        iphone.setName("SSR!");
        iphone.setProb(0.05D);

        Gift thanks = new Gift();
        thanks.setId(102);
        thanks.setName("SS");
        thanks.setProb(0.1D);

        Gift vip = new Gift();
        vip.setId(103);
        vip.setName("S!");
        vip.setProb(0.3D);

        Gift fouth = new Gift();
        fouth.setId(104);
        fouth.setName("A!");
        fouth.setProb(0.6D);

        List<Gift> list = new ArrayList<>();
        list.add(vip);
        list.add(thanks);
        list.add(iphone);
        list.add(fouth);
        int index = drawGift(list);
        System.out.println(list.get(index));
       /* for(int i=0;i<1000;i++){
            int index = drawGift(list);
            System.out.println(list.get(index));
        }*/
    }

    @Test
    public void run2(){

        // 随机生成一个随机数，并排序

        for (int i = 0; i < 100; i++) {
            double random = StandardNormalDistribution();
            System.out.println(random);
        }


    }

    //普通正态随机分布
//参数 u 均值
//参数 v 方差
    public static double NormalDistribution(float u,float v){
        java.util.Random random = new java.util.Random();
        return Math.sqrt(v)*random.nextGaussian()+u;
    }



    public static double StandardNormalDistribution() {
        java.util.Random random = new java.util.Random();
        return random.nextGaussian();

    }


}
